package com.js.rtu.fragment.forth;

import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.widget.Toolbar;

import com.js.rtu.R;
import com.js.rtu.base.BaseFragment;
import com.js.rtu.util.SPUtils;

import butterknife.BindView;
import butterknife.OnClick;


/**
 * Created by zwz on 2020/4/22.
 */
public class AIFragment extends BaseFragment {


    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.toolbar_title)
    TextView toolbarTitle;
    @BindView(R.id.btn_set)
    TextView btnSet;
    @BindView(R.id.edt_input1)
    EditText edtInput1;
    @BindView(R.id.edt_input2)
    EditText edtInput2;
    @BindView(R.id.edt_input3)
    EditText edtInput3;
    @BindView(R.id.edt_input4)
    EditText edtInput4;
    @BindView(R.id.edt_input5)
    EditText edtInput5;
    @BindView(R.id.edt_input6)
    EditText edtInput6;
    public static AIFragment newInstance() {

        Bundle args = new Bundle();
        AIFragment fragment = new AIFragment();
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    protected int getLayoutId() {
        return R.layout.fragment_tab_forth_settings_ai;
    }

    @Override
    protected void initView() {
        initToolbarNav(toolbar);
        toolbarTitle.setText("点测数据解析设置");
        edtInput1.setText(String.format("%s", (Float) SPUtils.get(_mActivity, "ai1", 600f)));
        edtInput2.setText(String.format("%s", (Float) SPUtils.get(_mActivity, "ai2", 600f)));
        edtInput3.setText(String.format("%s", (Float) SPUtils.get(_mActivity, "ai3", 600f)));
        edtInput4.setText(String.format("%s", (Float) SPUtils.get(_mActivity, "ai4", 600f)));
        edtInput5.setText(String.format("%s", (Float) SPUtils.get(_mActivity, "power", 3.7f)));
        edtInput6.setText(String.format("%s",  SPUtils.get(_mActivity, "fl", 6)));

    }


    @OnClick(R.id.btn_set)
    public void onViewClicked() {
        String ai1 =edtInput1.getText().toString().trim();
        String ai2 =edtInput2.getText().toString().trim();
        String ai3 =edtInput3.getText().toString().trim();
        String ai4 =edtInput4.getText().toString().trim();
        String power =edtInput5.getText().toString().trim();
        String fl =edtInput6.getText().toString().trim();
        if (ai1.isEmpty()||ai2.isEmpty()||ai3.isEmpty()||ai4.isEmpty()||power.isEmpty()||fl.isEmpty()){
            toastShow("参数不能为空");
            return;
        }
        if (Integer.parseInt(fl)<=0) {
            toastShow("必须大于0");
            return;
        }

        SPUtils.put(_mActivity,"ai1",  Float.parseFloat(ai1));
        SPUtils.put(_mActivity,"ai2",  Float.parseFloat(ai2));
        SPUtils.put(_mActivity,"ai3",  Float.parseFloat(ai3));
        SPUtils.put(_mActivity,"ai4",  Float.parseFloat(ai4));
        SPUtils.put(_mActivity,"power",  Float.parseFloat(power));
        SPUtils.put(_mActivity,"fl",  Integer.parseInt(fl));
        toastShow("设置成功");
    }

}
